import request from '@/utils/request';
import { parseStrEmpty } from '@/utils/base';

// 查询用户列表
export function listUser(data, query) {
  return request({
    url: '/web/base/system/user/page',
    method: 'post',
    params: query,
    data: data,
    encryptReq: true,
    hmacReq: true,
    decryptRes: true,
  });
}

// 查询用户详细
export function getUser(userId) {
  return request({
    url: '/web/base/system/user/info/' + parseStrEmpty(userId),
    method: 'get',
  });
}

// 新增用户
export function addUser(data) {
  return request({
    url: '/web/base/system/user/add',
    method: 'post',
    data: data,
    encryptReq: true,
    hmacReq: true,
  });
}

// 修改用户
export function updateUser(data) {
  return request({
    url: '/web/base/system/user/edit',
    method: 'post',
    data: data,
    encryptReq: true,
    hmacReq: true,
  });
}

// 修改用户证件号接口
export function editIndo(userId, idno) {
  const data = {
    userId,
    idno,
  };
  return request({
    url: '/web/base/system/user/editIdno/' + userId,
    method: 'post',
    data: data,
    encryptReq: true,
    hmacReq: true,
    decryptRes: true,
  });
}

// 查询用户明文详情接口
export function getPlainInfo(userId) {
  return request({
    url: '/web/base/system/user/plainInfo/' + userId,
    method: 'get',
    // encryptReq: true,
    hmacReq: true,
    decryptRes: true,
  });
}

// 删除用户
export function delUser(userId) {
  return request({
    url: '/web/base/system/user/delete/' + userId,
    method: 'post',
  });
}

// 恢复账号
export function recoveryUser(params) {
  return request({
    url: '/web/base/system/user/recovery',
    method: 'post',
    params,
    decryptRes: true,
  });
}

// 用户密码重置
export function resetUserPwd(userId, password) {
  const data = {
    userId,
    password,
  };
  return request({
    url: '/web/base/system/user/resetPwd',
    method: 'post',
    data: data,
    encryptReq: true,
    hmacReq: true,
    decryptRes: true,
  });
}

// 用户状态修改
export function changeUserStatus(userId, status) {
  const data = {
    userId,
    status,
  };
  return request({
    url: '/web/base/system/user/changeStatus',
    method: 'post',
    data: data,
  });
}

// 查询用户个人信息
export function getUserProfile() {
  return request({
    url: '/web/base/profile/user',
    method: 'get',
    encryptReq: true,
    hmacReq: true,
    decryptRes: true,
  });
}

// 修改用户个人信息
export function updateUserProfile(data) {
  return request({
    url: '/web/base/profile/user/edit',
    method: 'post',
    data: data,
    encryptReq: true,
    hmacReq: true,
  });
}

// 用户密码重置
export function updateUserPwd(oldPassword, newPassword) {
  const data = {
    oldPassword,
    newPassword,
  };
  return request({
    url: '/web/base/profile/user/updatePwd',
    method: 'post',
    data: data,
    encryptReq: true,
    hmacReq: true,
  });
}

// 修改用户excel密码
export function updateUserExcel(data) {
  return request({
    url: '/web/base/profile/user/updateExcelPwd',
    method: 'post',
    data: data,
    encryptReq: true,
    hmacReq: true,
  });
}

// 用户头像上传
export function uploadAvatar(data) {
  return request({
    url: '/web/base/profile/user/avatar',
    method: 'post',
    data: data,
  });
}

// 查询授权角色
export function getAuthRole(userId) {
  return request({
    url: '/web/base/system/user/authRole/' + userId,
    method: 'get',
  });
}

// 保存授权角色
export function updateAuthRole(data) {
  return request({
    url: '/web/base/system/user/authRole',
    method: 'post',
    params: data,
  });
}

// 查询部门下拉树结构
export function deptTreeSelect() {
  return request({
    url: '/web/base/system/user/deptTree',
    method: 'post',
  });
}

// 导入模板
export function userTemplate() {
  return request({
    url: '/web/base/system/user/template',
    method: 'post',
    responseType: 'blob',
    filename: `user_template_${new Date().getTime()}.xlsx`,
  });
}

// 导出
export function exportUser(data, params) {
  return request({
    url: '/web/base/system/user/export',
    method: 'post',
    data,
    params,
    responseType: 'blob',
    filename: `user_${new Date().getTime()}.xlsx`,
    encryptReq: true,
    hmacReq: true,
  });
}
